y_or_n = input("是否退出程序（y/n)?")
while y_or_n != "y":
    print("请输入以下信息，用空格分隔")
    input_str=input("性别 体重(kg) 身高(cm) 年龄:")
    str_list=input_str.split(" ")
    try:
        gender = str_list[0]
        weight = float(str_list[1])
        height = float(str_list[2])
        age = int(str_list[3])
        age_fail = 120
        weight_fail = 800
        height_fail = 350
        while age < age_fail and weight < weight_fail and height < height_fail:
            if gender == "男":
                bmr = (13.7 * weight) + (5.0 * height) - (6.8 * age) + 66
            elif gender == "女":
                bmr = (9.6 * weight) + (1.8 * height) - (1.7 * age) + 655
            else:
                bmr = -1
            if bmr != -1:
                print("基础代谢率:{}大卡".format(bmr))
                break
            else:
                print("暂不支持该性别")
                break
        while age>age_fail or weight>weight_fail or height>height_fail:
            print("输入信息有误，请仔细检查您所输入的信息！")
            input_str = input("请再次输入信息，用空格分隔：性别 体重(kg) 身高(cm) 年龄:")
            str_list = input_str.split(" ")
            gender = str_list[0]
            weight = float(str_list[1])
            height = float(str_list[2])
            age = int(str_list[3])
            age_fail = 120
            weight_fail = 800
            height_fail = 350
            if age > age_fail or weight > weight_fail or height > height_fail:
                continue
            else:
                if gender == "男":
                    bmr = (13.7 * weight) + (5.0 * height) - (6.8 * age) + 66
                elif gender == "女":
                    bmr = (9.6 * weight) + (1.8 * height) - (1.7 * age) + 655
                else:
                    bmr = -1
                if bmr != -1:
                    print("基础代谢率:{}大卡".format(bmr))
                    break
                else:
                    print("暂不支持该性别")
                    break
    except ValueError:
        print("请输入正确的信息!")
    except IndexError:
        print("输入的信息过少！")
    except:
        print("程序异常")
    print()
    y_or_n = input("是否退出程序（y/n)?")
